#{extends 'AdminM/frame.html' /}


#{set 'moreStyles'}

<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/stylesheets/Users/edit.scss'}" />
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/stylesheets/Users/message.scss'}" />

<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/pager/Pager.css'}" />
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/stylesheets/table.scss'}" />
#{/set}
#{set 'activeItem'}5#{/set}

<script src="@{'/public/pager/jquery.pager.js'}" type="text/javascript" charset="utf-8"></script>
<script src="@{'/public/javascripts/jquery-ui-1.8.10.custom.min.js'}" type="text/javascript" charset="utf-8"></script>
<div class="navigationBar">
	<table>
		<tr>
			<td><img src="@{'/public/images/navigationHouse.gif'}"></td>
			<td><strong>当前位置：</strong></td>
			<td>
				<a href="/admin">首页</a>
				>>
				<a href="#">消息管理</a>
				>>
				<font class="current">匿名咨询</font>
			</td>
		</tr>
	</table>
</div>
<script language="javascript">
	$(function(){
		
		//初始化翻页控件。
		$("#pager").pager(
			{
				pagenumber: ${queryBean.currentPage}, 
				pagecount: ${queryBean.totalPage}, 
				totalcount: ${queryBean.totalQuantity},
				buttonClickCallback: PageClick 
			}
		);
		
		//初始化回复窗口
		$("#dialog-form").dialog({autoOpen:false,modal:true,
        buttons:{提交:function(){reback();}}
			})
		});
	
	//翻页功能。
	PageClick = function(pageclickednumber) {
		$("#currentPage").val(pageclickednumber);
		doSearch();
	}
	
	//删除 留言
	function removeItem(id) {
		$.ajax({
			url: "/admin/message/"+id,
			//data: "id="+id,
			type: "DELETE",
			complete: function() {
				doSearch();
			}
		});
	}
	
	//审核通过
	function checkPassItem(id) {
		$.ajax({
			url: "/admin/message/pass",
			data: "id="+id,
			type: "POST",
			complete: function() {
				doSearch();
			}
		});
	}
	
	function checkFailItem(id) {
		$.ajax({
			url: "/admin/message/fail",
			data: "id="+id,
			type: "POST",
			complete: function() {
				doSearch();
			}
		});
	}

	//刷新页面
	function doSearch() {
		$("#form2").submit();
	}
	
	//打开回复窗口
	function openDialog(id){
	   $("#rebackidId").val(id);
       $("#dialog-form").dialog("open");
	}
	
	//回复 留言
	function reback() {
		var rebackid = $("#rebackidId").val();
		var rebackContent = $("#rebackContentId").val();
	
		$.ajax({
			url: "/admin/message/reply",
			data: "rebackid="+rebackid+"&"+"rebackContent="+rebackContent,
			type: "PUT",
			complete: function() {
				doSearch();
			}
		});
	}
</script>

<div class="messageBoard" id="right">
<div id="edit-comment">
	<table class="commodity-query">
		#{form @admin.Messages.indexQuestions(), name:'form2', id:'form2'}
			<input type="hidden" id="currentPage" name="queryBean.currentPage" value="${queryBean.currentPage}">
			每页
			<select name="queryBean.quantityEachPage" onchange="doSearch()">
				<option value="2" #{if queryBean.quantityEachPage==2} selected #{/if}>2</option>
				<option value="10" #{if queryBean.quantityEachPage==10} selected #{/if}>10</option>
				<option value="25" #{if queryBean.quantityEachPage==25} selected #{/if}>25</option>
				<option value="50" #{if queryBean.quantityEachPage==50} selected #{/if}>50</option>
			</select>
			条记录
			&nbsp;&nbsp;&nbsp;
			按照
			<select name="queryBean.orderby" onchange="doSearch()">
				<option value="lastModifiedAt" #{if queryBean.orderby=='lastModifiedAt'} selected #{/if}>修改日期</option>
				<option value="messageStatus" #{if queryBean.orderby=='messageStatus'} selected #{/if}>审核状态</option>
				<option value="author" #{if queryBean.orderby=='author'} selected #{/if}>留言者</option>
				<option value="title" #{if queryBean.orderby=='title'} selected #{/if}>标题</option>
				<option value="content" #{if queryBean.orderby=='content'} selected #{/if}>内容</option>
			</select>
			<select name="queryBean.isDesc" onchange="doSearch()">
				<option value="true" #{if queryBean.isDesc==true} selected #{/if}>降序</option>
				<option value="false" #{if queryBean.isDesc==false} selected #{/if}>升序</option>
			</select>
			排序
			&nbsp;&nbsp;&nbsp;
			关键字
			<input type="text" maxlength="20" name="queryBean.keyword" value="${queryBean.keyword}">
		#{/form}
	</table>
</div>

<div>
	<table class="common-table">
		<thead>
			<tr>
				<th width="70px;">留言者</th>
				<th width="70px;">标题</th>
				<th>内容</th>
				<th width="80px;">时间</th>
				<th width="50px;">状态</th>
				<th width="50px;">审核</th>
				<th width="50px;">操作</th>
				<th width="25px;">删</th>
			</tr>
		</thead>
		<tbody>
		#{if msgs}
			#{list items:msgs, as:'msg'}
				<tr>
					<td class="main_message">${msg.author}</td>					
					<td class="main_message">${msg.title}</td>
					<td class="msgContent main_message">${msg.content}</td>
					<td>${msg.lastModifiedAt.format("yyyy-MM-dd hh:mm:ss")}</td>
					<td>
						#{if msg.messageStatus == models.Message.MessageStatus.NEW}<font class="important_1_1">未审核</font>#{/if}
						#{if msg.messageStatus == models.Message.MessageStatus.PASS}<font class="important_2_1">已通过</font>#{/if}
						#{if msg.messageStatus == models.Message.MessageStatus.FAIL}不通过#{/if}
					</td>
					<td>
						#{if msg.messageStatus != models.Message.MessageStatus.PASS}
							<a class="editer" href="javascript:checkPassItem(${msg.id})">[ 通过 ]</a>
						#{/if}
						#{if msg.messageStatus != models.Message.MessageStatus.FAIL}
							<a class="editer" href="javascript:checkFailItem(${msg.id})">[不通过]</a>
						#{/if}
					</td>
					<td>
						<font color="red"><a href="javascript:openDialog(${msg.id});" >[回复]</a></font>
					</td>
					<td>
						<a href="javascript:removeItem(${msg.id})" title="删除">
							<img class="minImg" src="@{'public/images/delete.gif'}">
						</a>
					</td>
				</tr>
				#{if msg.replys}	
		      		#{list items:msg.replys, as:'reply'}
		      			<tr>
			      			<td colspan="2" style="text-align:right;">
			      				管理员
			      				#{if reply.createByAdmin}
			      				(<font class="important_1_1">${reply.createByAdmin.username}</font>)
			      				#{/if}
			      				[回复]:&nbsp;
			      			</td>
							<td class="msgContent">${reply.content}</td>
							<td>${reply.lastModifiedAt.format("yyyy-MM-dd hh:mm:ss")}</td>
							<td></td>
							<td></td>
							<td></td>
							<td>
								<a href="javascript:removeItem(${reply.id})" title="删除">
									<img class="minImg" src="@{'public/images/delete.gif'}">
								</a>
							</td>
			      		</tr>	
					#{/list}
			    #{/if}
				#{/list}
			#{/if}
			#{else}
				<tr>
					<td colspan="6">没有查询到记录。</td>
				</tr>
			#{/else}
		</tbody>
	</table>
</div>

<div id="dialog-form" class="ui-widget ui-widget-content ui-corner-all" title="留言回复">
    <form id="login-form">
    <input type="hidden" id="rebackidId" name="rebackid">
    <textarea wrap="virtual" rows="4" 
        cols="50" id="rebackContentId" name="rebackContent"></textarea>
    </form>
</div>
	<div style="font-size:1.3em;">
		<div id="pager"></div><br>
	</div>
</div>